﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System.Web;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;
using jQuery.ScriptManager;

namespace JQueryWebParts.RoundedCorners
{
    public class SPRoundedCorners : Microsoft.SharePoint.WebPartPages.WebPart
    {
        protected jQueryManager jqueryManager = null;
        protected Literal placeHolderLiteral = new Literal();
        protected string cornerType = "";

        protected override void OnInit(EventArgs e)
        {
            jqueryManager = jQueryManager.GetCurrent(Page);
            if (jqueryManager == null)
            {
                jqueryManager = new jQueryManager();
                Page.Controls.Add(jqueryManager);
            }
            Page.ClientScript.RegisterClientScriptInclude("JCorner", Page.ClientScript.GetWebResourceUrl(this.GetType(), "JQueryWebParts.js.jquery.corner.js"));
            base.OnInit(e);
        }

        protected override void CreateChildControls()
        {
            this.Controls.Add(placeHolderLiteral);
            base.CreateChildControls();
        }


        protected override void OnPreRender(EventArgs e)
        {
            placeHolderLiteral.Text = "<div id=\"corner" + this.ID + "\" class=\"rounded\"></div>";

            jqueryManager.ReadyFunctions.Add(new StartFunction("jQuery('#corner" + this.ID + "').corner('" + cornerType + "');"));

            base.OnPreRender(e);
        }

        [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
         System.Web.UI.WebControls.WebParts.WebDisplayName("Corner Type"),
         System.Web.UI.WebControls.WebParts.WebDescription("Examples: '25px', 'notch bottom'"),
         System.Web.UI.WebControls.WebParts.Personalizable(
         System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
         System.ComponentModel.Category("Settings"),
         System.ComponentModel.DefaultValue("")
        ]
        public string CornerType
        {
            get
            {
                return cornerType;
            }

            set
            {
                cornerType = value;
            }
        }

    }
}
